import tkinter as tk


def disable_close():
    root = tk.Tk()

    def do_nothing():
        pass

    root.protocol("WM_DELETE_WINDOW", do_nothing)

    def enable_close():
        def close_window():
            root.destroy()

        root.protocol("WM_DELETE_WINDOW", close_window)

    btn = tk.Button(root, text="启用关闭按钮", command=enable_close)
    btn.pack()
    label = tk.Label(root, text="初始时关闭按钮被禁用，点击按钮可启用")
    label.pack()
    root.mainloop()


if __name__ == "__main__":
    disable_close()